package testRectangle;

public class Rectangle {
	public Point leftBottom;
	public Point rightTop;

	public Rectangle(Point min, Point max) {
		leftBottom = min;
		rightTop = max;
	}

	public static int getIntersectionRectangleArea(Rectangle rect1, Rectangle rect2) {
		int result = 0;

		int minX = Math.max(rect1.leftBottom.x, rect2.leftBottom.x);
		int minY = Math.max(rect1.leftBottom.y, rect2.leftBottom.y);
		int maxX = Math.min(rect1.rightTop.x, rect2.rightTop.x);
		int maxY = Math.min(rect1.rightTop.y, rect2.rightTop.y);

		int a = maxX - minX;
		int b = maxY - minY;
		if (a > 0 && b > 0) {
			result = a * b;
			if (a != result / b) {
				result = -1;
			}
		}

		return result;
	}

	public static double getTriangleArea(Point A, Point B, Point C) {
		Point AB = new Point();
		Point BC = new Point();
		AB.x = B.x - A.x;
		AB.y = B.y - A.y;
		BC.x = C.x - B.x;
		BC.y = C.y - B.y;
		return Math.abs((AB.x * BC.y - AB.y * BC.x) / 2.0);
	}
}
